/*
 * Copyright 2007 Dan Hodge
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.datajanitor.baja.data;

import java.io.Serializable;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Represents information about a user. 
 */
public class UserInfo implements Serializable {
    private static final long serialVersionUID = -5992400205454267291L;
    private String login;
    private String email;
    private int accessId;
    private int userId;
    private long space;
    private long used;
    
    public UserInfo(NodeList nodes) {
        for (int i = 0, len = nodes.getLength(); i< len; i++) {
            Node curNode = nodes.item(i);
            String nodeName = curNode.getNodeName();
            String nodeValue = curNode.getNodeValue();
            
            if ("login".equals(nodeName)) {
                this.login = nodeValue;
            } else if ("email".equals(nodeName)) {
                this.email = nodeValue;    
            } else if ("access_id".equals(nodeName)) {
                this.accessId = Integer.parseInt(nodeValue);    
            } else if ("user_id".equals(nodeName)) {
                this.userId = Integer.parseInt(nodeValue);    
            } else if ("space_amount".equals(nodeName)) {
                this.space = Long.parseLong(nodeValue);    
            } else if ("space_user".equals(nodeName)) {
                this.used = Long.parseLong(nodeValue);    
            }     
        }
    }
    
    public UserInfo(String login, String email, int accessId, int userId, long total, long used) {
        this.login = login;
        this.email = email;
        this.accessId = accessId;
        this.userId = userId;
        this.space = total;
        this.used = used;
    }
    
    public int getAccessId() {
        return accessId;
    }

    public String getEmail() {
        return email;
    }

    public String getLogin() {
        return login;
    }

    public long getSpace() {
        return space;
    }

    public long getUsed() {
        return used;
    }

    public int getUserId() {
        return userId;
    }
    
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(getClass().getName()).append("[login=").append(this.login).append(",email=")
               .append(this.email).append(",accessId=").append(this.accessId).append(",userId=")
               .append(this.userId).append(",totalSpace=").append(this.space).append(",usedSpace=")
               .append(this.used).append("]");
        
        return builder.toString();
    }
}
